<?php

/*
 * contrat-type/load-index.phtml
 */
?>
<?php
// Variables
$typeListe = $this->typeListe;
?>
<div class="list-container">
    <table class="table table-striped list-table">
	<thead>
	    <tr>
		<td width="50%">Libellé</td>
		<td width="20%">Abréviation</td>
		<td width="20%">Coefficient</td>
		<td width="10%">&nbsp;</td>
	    </tr>
	</thead>
	<tbody>
	    <?php foreach ($typeListe as $type): ?>
    	    <tr>
    		<td>
		    <a href="#" class="edit-libelle" data-type="text" data-pk="<?php echo $type->id; ?>" data-name="libelle"><?php echo $type->libelle; ?></a>
    		</td>
    		<td>
		    <a href="#" class="edit-abrev" data-type="text" data-pk="<?php echo $type->id; ?>" data-name="abrev"><?php echo $type->abrev; ?></a>
    		</td>
    		<td>
		    <a href="#" class="edit-coef" data-type="text" data-pk="<?php echo $type->id; ?>" data-name="coef"><?php echo $type->coef; ?></a>
    		</td>
		<td>
    		    <a href='#' data-id="<?php echo $type->id; ?>" data-libelle="<?php echo $type->libelle; ?>" class="delete-type">
    			<img src='<?php echo $this->basePath() . '/img/rhx/delete-16x16.png' ?>' alt='Effacer' title='Effacer'>
    		    </a>
    		</td>
    	    </tr>
	    <?php endforeach; ?>
	</tbody>
    </table>
</div>

<script type="text/javascript">
    // Démarrage
    $(function(){
	// Effacer
	$('.delete-type').click(function(e){
	    e.preventDefault();
	    libelle = $(this).attr('data-libelle');
	    id = $(this).attr('data-id');
	    conf = confirm("Voulez-vous effacer le type de Contrat " + libelle + " ?");
	    if(!conf){
		return false;
	    }
	    ajax = $.ajax({
		type: 'post',
		url : '<?php echo $this->url('RHX/default', array('controller'	 => 'contrattype', 'action'	 => 'delete')) ?>',
		data: '&id=' + id
	    });
	    ajax.done(function(result){
		if(!result.done){
		    alert("Une erreur est survenue !");
		}
		window.location.reload();
	    });
	});
	// Champ editable
	$('.edit-libelle').editable({
	    title: 'Edition du libellé',
	    url : '<?php echo $this->url('RHX/default', array('controller'	 => 'contrattype', 'action'	 => 'edit')) ?>'
	});
	$('.edit-abrev').editable({
	    title: 'Edition d\'abréviation',
	    url : '<?php echo $this->url('RHX/default', array('controller'	 => 'contrattype', 'action'	 => 'edit')) ?>'
	});
	$('.edit-coef').editable({
	    title: 'Edition du coefficient',
	    url : '<?php echo $this->url('RHX/default', array('controller'	 => 'contrattype', 'action'	 => 'edit')) ?>'
	});
    });
</script>